﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using DAO;

namespace BLO
{
    public class HoaDonNhap_Blo
    {
        private readonly HoaDonNhap_Dao _hoaDonNhapDao = new HoaDonNhap_Dao();
        public DataSet GetAllObject()
        {
            return _hoaDonNhapDao.GetAllObject();
        }

        public int AddObject(string mahdn, string ngaynhap, string manv, string mancc, string masp, int soluong, int khuyenmai, decimal gianhap)
        {
            return _hoaDonNhapDao.AddObject(mahdn, ngaynhap, manv, mancc, masp, soluong, khuyenmai, gianhap);
        }

        public int EditObject(string mahdn, string ngaynhap, string manv, string mancc, string masp, int soluong, int khuyenmai, decimal gianhap)
        {
            if (string.IsNullOrEmpty(mahdn) || string.IsNullOrEmpty(ngaynhap) || string.IsNullOrEmpty(mancc) || soluong < 0 || 
                khuyenmai < 0 || khuyenmai > 100 || gianhap < 0 || gianhap > decimal.MaxValue)
                return -1;
            return _hoaDonNhapDao.EditObject(mahdn, ngaynhap, manv, mancc, masp, soluong, khuyenmai, gianhap);
        }

        public int DeleteObject(string mahdn)
        {
            if (string.IsNullOrEmpty(mahdn)) 
                return -1;
            return _hoaDonNhapDao.DeleteObject(mahdn);
        }

        public int AutoIncrementIdObject()
        {
            return _hoaDonNhapDao.AutoIncrementIdObject();
        }
        public DataTable FindObject(string condition)
        {
            if (string.IsNullOrEmpty(condition))
                return null;
            return _hoaDonNhapDao.FindObject(condition);
        }

        public DataSet GetHoaDons(string mancc)
        {
            if (string.IsNullOrEmpty(mancc))
                return null;
            return _hoaDonNhapDao.GetHoaDons(mancc);
        }
    }
}
